﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Experiment2
{
    
    /// <summary>
    /// 信用卡类
    /// </summary>
    class CreditCard
    {
        //持有人名
        public string name;
        //信用卡额度
        public const double CreditCardmax = 3000;
        //信用卡欠款
        public double _CredMoney;
        //还款日期
        public int DueDay;
        //绑定储蓄卡集合
        public DepositCards Dc;


        public CreditCard(string name, double Credmoney, int DueDay, DepositCards Dc)
        {
            this.name = name;
            this.CredMoney = Credmoney;
            this.DueDay = DueDay;
            this.Dc = Dc;
        }
        public double CredMoney
        {
            get { return _CredMoney; }
            //还款金额限制
            set {
                if (value < 0 || value > CreditCardmax)
                {
                    Console.WriteLine("=========================");
                    Console.WriteLine("{0}的还款金额错误最大为{1}请重新输入：", this.name,CreditCardmax);
                   while( !double.TryParse(Console.ReadLine(),out value))
                    {
                      Console.WriteLine("{0}的还款金额错误最大为{1}请重新输入：", this.name, CreditCardmax);
                    }
                }
                
                _CredMoney = value; }
        }
        /// <summary>
        /// 还款函数
        /// </summary>
        public void   Repaym()
        {
            int a = Dc.n;
            for(int i = 0; i < a; i++)
            {
                if (this.Dc.Dc[i].getDepositMoney() > this.CredMoney)
                {
                Console.WriteLine("今天是{0}", DateTime.Now);
                Console.WriteLine("用户{0}已还款。",this.name);
                Console.WriteLine("还款账户{0}账户余额{1}。",this.Dc.Dc[i].name,this.Dc.Dc[i].getDepositMoney());
                this.Dc.Dc[i].setDepositMoney(this.Dc.Dc[i].getDepositMoney() - this.CredMoney);
                Console.WriteLine("信用额度为{0} ", CreditCardmax);
                Console.WriteLine("还款金额{0}。", this.CredMoney);
                Console.WriteLine("还款后余额{0}。", this.Dc.Dc[i].getDepositMoney());
                Console.WriteLine();
                    return;
                }
            }
            Console.WriteLine("今天是{0}", DateTime.Now);
            Console.WriteLine("还款人{0}", this.name);
            Console.WriteLine("还款金额{0}。", this.CredMoney);
            Console.WriteLine("账户余额不足, 请即时充值。");
                     return;
        }
        /// <summary>
        /// 无需还款函数
        /// </summary>
        public void Norepaym()
        {
            Console.WriteLine("今天是{0}。", DateTime.Now);
            Console.WriteLine("用户{0}未到还款日期，无需还款", this.name);
            Console.WriteLine();
        }
    }

    /// <summary>
    /// 储蓄卡类
    /// </summary>
    public class DepositCard
    {
        public string name;
        private double money;
            public DepositCard(string name, double money)
        {
            this.name = name;
            this.money = money;
        }
        public DepositCard(string name) : this(name, 0)
        {
        }
        /// <summary>
        /// 获取余额
        /// </summary>
        /// <returns>余额</returns>
        public double getDepositMoney()
        {
            return this.money;
        }
        /// <summary>
        /// 设置余额
        /// </summary>
        /// <param name="r">余额</param>
        public void setDepositMoney(double r)
        {
            this.money = r;
        }
    }

    /// <summary>
    /// 储蓄卡集合类
    /// </summary>
    public class DepositCards
    {
        public DepositCard[] Dc;
        public int n;
        public DepositCards(DepositCard[] Dc, int n)
        {
            this.n = n;
            this.Dc = Dc;
        }
    }


    /// <summary>
    /// 扣款委托类
    /// </summary>
    public class RepayDelegate
    {
        /// <summary>
        /// 扣款委托
        /// </summary>
        public delegate void RepayMoney();
        public event RepayMoney Dorepay;
        /// <summary>
        /// 执行事件
        /// </summary>
        public void NotifyRepay()
        {
            if (Dorepay != null)
            {
                Console.WriteLine("=========================");
                Dorepay();
            }
        }
    }

}
